package com.party.core.service.gift.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.gift.GiftOrderReadDao;
import com.party.core.dao.write.gift.GiftOrderWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.gift.GiftOrder;
import com.party.core.model.gift.GiftOrderListOutput;
import com.party.core.service.gift.IGiftOrderService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Author: Administrator.
 * @Description: 礼包领取
 * @Date:Created in 2017/11/15 0015 上午 10:36.
 */
@Service
public class GiftOrderService implements IGiftOrderService {
    @Autowired
    private GiftOrderReadDao giftOrderReadDao;
    @Autowired
    private GiftOrderWriteDao giftOrderWriteDao;

    @Override
    public String insert(GiftOrder t) {
        BaseModel.preInsert(t);
        boolean result = giftOrderWriteDao.insert(t);
        if (result) {
            return t.getId();
        }
        return null;
    }

    @Override
    public boolean update(GiftOrder t) {
        t.setUpdateDate(new Date());
        return giftOrderWriteDao.update(t);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return giftOrderWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return giftOrderWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return giftOrderWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return giftOrderWriteDao.batchDelete(ids);
    }

    @Override
    public GiftOrder get(String id) {
        return giftOrderReadDao.get(id);
    }

    @Override
    public List<GiftOrder> listPage(GiftOrder t, Page page) {
        return giftOrderReadDao.listPage(t, page);
    }

    @Override
    public List<GiftOrder> list(GiftOrder t) {
        return giftOrderReadDao.listPage(t, null);
    }

    @Override
    public List<GiftOrder> batchList(Set<String> ids, GiftOrder t, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return giftOrderReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public List<GiftOrderListOutput> webListPage(GiftOrderListOutput giftOrder, Map<String, Object> params, Page page) {
        return giftOrderReadDao.webListPage(giftOrder, params, page);
    }

    @Override
    public GiftOrder getUnique(GiftOrder giftOrder) {
        return giftOrderReadDao.getUnique(giftOrder);
    }

    @Override
    public void deleteByGiftId(String giftId) {
        giftOrderWriteDao.deleteByGiftId(giftId);
    }
}
